package cn.xdf.docenhance

import android.graphics.Bitmap
import android.util.Log
import com.google.mlkit.vision.docscan.pipeline.shadow.ShadowRemovalJNI

/**
 * 去阴影独立能力：优先 JNI，失败时回退原图。
 */
object ShadowRemovalEngine {
    enum class Mode { RGB, YCBR }

    fun removeShadow(input: Bitmap, mode: Mode = Mode.RGB): Bitmap {
        val out = Bitmap.createBitmap(input.width, input.height, Bitmap.Config.ARGB_8888)
        return try {
            when (mode) {
                Mode.RGB -> ShadowRemovalJNI.applyBakoRGB(input, out)
                Mode.YCBR -> ShadowRemovalJNI.applyBakoYCBR(input, out)
            }
            out
        } catch (t: Throwable) {
            Log.w("ShadowRemovalEngine", "JNI shadow removal failed", t)
            input
        }
    }
}


